<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 输入： n = 19
        // 输出： true
        // 解释：
        // 12 + 92 = 82
        // 82 + 22 = 68
        // 62 + 82 = 100
        // 12 + 02 + 02 = 1

        var isHappy = function (n) {
            if (n === 1) return true
            const list = new Set()
            console.log(list);
            while (!list.has(n)) {
                list.add(n)
                let sum = 0
                while (n) {
                    const value = n % 10
                    sum += value * value
                    n = parseInt(n / 10)
                }
                if (sum === 1) {
                    return true
                }
                n = sum
            }
            return false
        };



        console.log(isHappy(119));
    </script>
</body>

</html>